package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdModelProduceConfigQueryVO;
import com.yunxi.otd.pojo.OtdModelProduceConfigVO;
import com.yunxi.otd.service.OtdModelProduceConfigDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 车型投产日设置 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-07-09
 */
@RestController
@RequestMapping("/admin/otd/modelconfig/")
@Api(tags = "OTD:MODELCONFIG", description = "车型投产日设置接口")
public class OtdModelProduceConfigController {

    private static final Logger logger = LoggerFactory.getLogger(OtdModelProduceConfigController.class);

    @Autowired
    OtdModelProduceConfigDubboService otdModelProduceConfigDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(OtdModelProduceConfigQueryVO queryVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil
            .ok(otdModelProduceConfigDubboService.findPageByVO(queryVO, pageNum, pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(String id) {
        return ResponseUtil.ok(otdModelProduceConfigDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody OtdModelProduceConfigVO vo, @CurrentUser LoginInfo info) {
        logger.info("车型投产日保存...");
        return otdModelProduceConfigDubboService.saveOrUpdate(vo, info);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    public ApiResult remove(@RequestBody List<String> ids) {
        otdModelProduceConfigDubboService.removeByIds(ids);
        return ResponseUtil.ok();
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出excel")
    public Object export(OtdModelProduceConfigQueryVO queryVO) {
        return ResponseUtil.ok(otdModelProduceConfigDubboService.export(queryVO));
    }
}
